<include file="Public/min-header"/>
<div class="wrapper">
    <section class="content">
        <div class="container-fluid">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="navbar navbar-default">
                        <form action="{:U('seller/Order/ajax_order_goods')}" id="search-form2" class="navbar-form form-inline" method="post" onsubmit="return false">

                            <div class="form-group">
                                <label class="control-label" for="input-order-id">关键词</label>
                                <div class="input-group">
                                    <input type="text" name="keywords" value="{$keywords}" placeholder="搜索词" id="input-order-id" class="form-control" style="width:250px;">
                                </div>
                            </div>
                            <button type="submit" id="button-filter search-order" class="btn btn-primary" onclick="ajax_get_table('search-form2',1);"><i class="fa fa-search"></i>查找</button>
                        </form>
                    </div>
                    <div id="ajax_return">
                        <!--商品列表
                          <div class="table-responsive">
                              <table class="table table-bordered table-hover" id="goos_table">
                                  <thead>
                                  <tr>
                                      <td class="text-left">商品名称</td>
                                      <td class="text-left">价格</td>
                                      <td class="text-left">库存</td>
                                      <td class="text-left">选择</td>
                                      <td class="text-left">操作</td>
                                  </tr>
                                  </thead>
                                  <tbody>
                                  <volist name="goodsList" id="list">


                                      <if condition="$list['spec_goods'] neq null">
                                           <volist name="list['spec_goods']" id="spec_goods">
                                               <if condition="$spec_goods[is_yes] == 0">
                                                  <tr>
                                                      <td class="text-left">{$list.goods_name|getSubstr=0,33}&nbsp;&nbsp;&nbsp;(&nbsp;{$spec_goods[key_name]}&nbsp;) <span style="color:red;">{$spec_goods[price]['prom_msg']}</span></td>
                                                      <td class="text-left">{$spec_goods[price]['price']}</td>
                                                      <td class="text-left">{$spec_goods[store_count]}</td>
                                                      <td class="text-left" style="width: 200px;">
                                                          <!--<input type="text" name="goods_id[{$list.goods_id}][{$spec_goods[key]}][goods_num]"   value="1" class="input-sm" style="display:none;" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
                                                          <input type="text" name="goods_id[{$list.goods_id}][{$spec_goods[key]}][goods_num]" value="1" class="input-sm" style="display:none;" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')"/>
                                                          <input type="checkbox"/>
                                                      </td>
                                                      <td><a href="javascript:" onclick="javascript:$(this).parent().parent().remove();">删除</a></td>
                                                  </tr>
                                               </if>
                                             </volist>
                                       <else/>
                                          <tr>
                                              <td class="text-left">{$list.goods_name|getSubstr=0,33} {$list.huodong}</td>
                                              <td class="text-left">{$list.shop_price}</td>
                                              <td class="text-left">{$list.store_count}</td>
                                              <td class="text-left">
                                                   <!--<input type="text" name="goods_id[{$list.goods_id}][key][goods_num]" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" value="1" class="input-sm" style="display:none;" />
                                                   <input type="text" name="goods_id[{$list.goods_id}][{$spec_goods[key]}][goods_num]" value="1" class="input-sm" style="display:none;" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')"/>
                                                   <input type="checkbox"/>
                                              </td>
                                              <td><a href="javascript:void(0)" onclick="javascript:$(this).parent().parent().remove();">删除</a></td>
                                          </tr>
                                       </if>
                                  </volist>
                                      <tr>
                                          <td class="text-right" colspan="5">
                                              <a href="javascript:void(0)" onclick="select_goods();" class="btn btn-info">确定</a>
                                          </td>
                                     </tr>
                                  </tbody>
                              </table>
                          </div>
                          -->
                    </div>
                </div>
            </div>
        </div>
    </section>
    <script>
        function select_goods()
        {
            if($("input[type='checkbox']:checked").length == 0)
            {
                layer.alert('请选择商品', {icon: 2}); //alert('请选择商品');
                return false;
            }
            // 将没选中的复选框所在的  tr  remove  然后删除复选框
            $("input[type='checkbox']").each(function(){
                if($(this).is(':checked') == false)
                {
                    $(this).parent().parent().remove();
                }
                $(this).siblings().show();
                $(this).remove();
            });
            $(".btn-info").remove();
            javascript:window.parent.call_back($('#goos_table').html().replace(/选择/,'购买数量'));
        }

        $(document).ready(function(){
            ajax_get_table('search-form2',1);

        });

        function ajax_get_table(tab,page){
            cur_page = page; //当前页面 保存为全局变量
            $.ajax({
                type : "POST",
                url:"/index.php/Seller/Order/ajax_order_goods/p/"+page,//+tab,
                data : $('#'+tab).serialize(),// 你的formid
                success: function(data){
                    $("#ajax_return").html('');
                    $("#ajax_return").append(data);
                    // 恢复当前页面的选中状态
                    $('input.input-sm.goods-quantity').each(function(){
                        // console.log($(this).attr('key'));
                        if(selectedUserIds.indexOf($(this).attr('key')) !== -1) {
                            $(this).prop('checked', true);
                        }
                    });
                }
            });
        }
        // 全局变量存储选中的用户ID
        // var selectedUserIds = [];
        // console.log('初始化：'+selectedUserIds);
        function doconfirm(){
            // 获取所有选中的用户ID（包括iframe中的）
            var allSelectedIds = selectedUserIds;
            // console.log(allSelectedIds)
            if(selectedUserIds.length == 0) {
                layer.alert('请选择商品', {icon: 2});
                return false;
            } else {
                // 创建隐藏字段存储所有选中的ID
                $('#form-user').append('<input type="hidden" name="selected_user_ids" value="'+allSelectedIds.join(',')+'">');
                $('#form-user').submit();
            }
        }
    </script>
</div>
</body>
</html>